import 'package:flutter/material.dart';
import 'package:happy_elf_app/apis/home.dart';
import 'package:happy_elf_app/utils/adaption.dart';

class giveupModal {
  static late Function success; // 回掉
  static dynamic buildContext;
  static bool isModel = false;
  static Function? setModalState; // 更新
  static List data = []; // 放弃的任务
  static String taskId = '';

  static init(
      {required Function callBack, required context, required String taskId}) {
    success = callBack;
    buildContext = context;
    taskId = taskId;
    isModel = false;
    model(buildContext);
  }

  static model(buildContext) {
    if (isModel) return;
    isModel = true;
    showDialog(
        barrierDismissible: false, // 禁用点击空白处关闭对话框
        context: buildContext,
        builder: (BuildContext context) {
          return StatefulBuilder(builder: (context, setSelfState) {
            setModalState = setSelfState;
            return UnconstrainedBox(
                child: ClipRRect(
              borderRadius: BorderRadius.circular(20.px),
              child: Container(
                width: 300,
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.circular(20.px),
                ),
                child: Column(
                  children: [
                    Stack(
                      children: [
                        Container(
                          child: Text('我发现你已经3次放弃任务啦，请问发生了什么吗'),
                        )
                      ],
                    ),
                    Container(
                      child: Row(
                        children: [
                          Text('太难了'),
                          Text('简化任务'),
                        ],
                      ),
                    ),
                    Container(
                      child: Row(
                        children: [
                          Text('太无聊了'),
                          Text('趣味化任务'),
                        ],
                      ),
                    ),
                    Row(
                      children: [
                        GestureDetector(
                          child: Container(
                            child: Text('关闭'),
                          ),
                          onTap: () {
                            Navigator.of(context).pop();
                          },
                        ),
                        GestureDetector(
                          child: Container(
                            child: Text('确定'),
                          ),
                          onTap: () {
                            getGiveUpTask;
                            Navigator.of(context).pop();
                            modifyModal();
                          },
                        )
                      ],
                    )
                  ],
                ),
              ),
            ));
          });
        });
  }

  static void getGiveUpTask() async {
    //
    final id = '';
    var res = await Home().getgiveUp(id);
    if (res['code'] == 200) {
      data = res['data'];
    }
  }

  static modifyModal() {
    showDialog(
        barrierDismissible: false, // 禁用点击空白处关闭对话框
        context: buildContext,
        builder: (BuildContext context) {
          return StatefulBuilder(builder: (context, setSelfState) {
            setModalState = setSelfState;
            return UnconstrainedBox(
                child: ClipRRect(
                    borderRadius: BorderRadius.circular(20.px),
                    child: Container(
                      width: 300,
                      decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.circular(20.px),
                      ),
                      child: Column(
                        children: [
                          Row(
                            children: [
                              GestureDetector(
                                child: Container(
                                  child: Text('简化任务'),
                                ),
                                onTap: () {},
                              ),
                              GestureDetector(
                                child: Container(
                                  child: Text('拆分任务'),
                                ),
                                onTap: () {},
                              )
                            ],
                          ),
                          Row(
                            children: [
                              GestureDetector(
                                child: Container(
                                  child: Text('关闭'),
                                ),
                                onTap: () {
                                  Navigator.of(context).pop();
                                },
                              ),
                              GestureDetector(
                                child: Container(
                                  child: Text('确定'),
                                ),
                                onTap: () {
                                  Navigator.of(context).pop();
                                  modifyModal();
                                },
                              )
                            ],
                          )
                        ],
                      ),
                    )));
          });
        });
  }
}
